package com.ycsj.goldmedalnewconcept.teacher.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.HttpAddress;
import com.ycsj.goldmedalnewconcept.common.bean.UnitInfo;
import com.ycsj.goldmedalnewconcept.common.http.HttpCallBack;
import com.ycsj.goldmedalnewconcept.common.http.HttpUtils;
import com.ycsj.goldmedalnewconcept.master.bean.TeachingObjectiveResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * 教学与反思
 */
public class TeachingObjectivesActivity extends BaseActivity {

    private TextView tv_techingobjective;
    private ImageView iv_back;
    private TextView tv_difficultpoint;
    private TextView tv_teachingtitle;
    private TextView tv_sikao;
    private String role;
    private String class_id;
    private String user_id;
    private String unit;
    //    private int Lesson;
    private Intent intent;
    //当前页面的单元信息对象和单元号
    private UnitInfo.LessonListBean info;

    //班级号
    private String classNum;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_teachingobjectives;
    }


    /**
     * 跳转到当前界面的方法
     *
     * @param info     当前界面的单元信息
     * @param unit     单元号
     * @param classNum 班级号
     */
    public static void goActivity(Context context, UnitInfo.LessonListBean info, String unit, String classNum) {
        Intent it = new Intent(context, TeachingObjectivesActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("data", info);
        bundle.putString("unit", unit);
        bundle.putString("classnum", classNum);
        it.putExtras(bundle);
        context.startActivity(it);

    }

    @Override
    protected void init() {

        //初始化View方法
        initView();

        //获取传值数据
        initIntent();

        //设置点击事件
        setOnListener();

        //请求数据
        httpData("17");
    }

    /**
     * 获取传值数据
     */
    private void initIntent() {

        info = (UnitInfo.LessonListBean) getIntent().getSerializableExtra("data");

        unit = getIntent().getStringExtra("unit");

        classNum = getIntent().getStringExtra("classnum");

        role = SPUtil.getString(this, "role");// 获取账号角色类型

        if ("3".equals(role)) {

            tv_sikao.setText("教师的思考");

        } else if ("2".equals(role)) {

            tv_sikao.setText("我的思考");

        } else if ("1".equals(role)) {

            tv_sikao.setVisibility(tv_sikao.GONE);

            tv_difficultpoint.setVisibility(tv_difficultpoint.GONE);

        }
    }

    /**
     * 初始化View方法
     */
    private void initView() {

        tv_techingobjective = (TextView) findViewById(R.id.tv_techingobjective);
        tv_teachingtitle = (TextView) findViewById(R.id.tv_teachingtitle);
        tv_difficultpoint = (TextView) findViewById(R.id.tv_difficultpoint);
        tv_sikao = (TextView) findViewById(R.id.tv_sikao);
        iv_back = (ImageView) findViewById(R.id.iv_back);
    }

    /**
     * 初始化监听
     */
    private void setOnListener() {
        tv_sikao.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

//					Intent intent = new Intent(TeachingObjectivesActivity.this,
//							FansiActivity.class);
//                    intent.putExtra("class_id1", class_id);
//                    intent.putExtra("lesson1", Lesson);
//                    intent.putExtra("unit1", unit);
//					startActivity(intent);

            }
        });

        tv_techingobjective.setMovementMethod(ScrollingMovementMethod
                .getInstance());
        iv_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tv_difficultpoint.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String string = tv_difficultpoint.getText().toString();
                if ("重难点".equals(string)) {

                    tv_difficultpoint.setText("教学目标");

                    tv_teachingtitle.setText("重难点");

                    httpData("16");

                } else if (!"重难点".equals(string)) {
                    tv_difficultpoint.setText("重难点");
                    tv_teachingtitle.setText("教学目标");

                    httpData("17");
                }
            }
        });
    }

    /**
     * 请求数据
     */
    private void httpData(String type) {
        Map<String, String> map = new HashMap<>();
        map.put("type", type);
        map.put("unit", unit + "");

        HttpUtils.post(HttpAddress.TEACHINGOBJECTIVES, map, this,
                new HttpCallBack<TeachingObjectiveResponse>() {

                    @Override
                    public void onSuccess(TeachingObjectiveResponse info) {


                        tv_techingobjective
                                .setText(Html.fromHtml(info.content));
                    }

                    @Override
                    public void onError(String e) {
                        ToastUtils.showShort("网络错误");
                    }
                });
    }
}
